<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>编辑检查项</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../static/css/style.css" th:href="@{/css/style.css}"/>
</head>
<body>
<div th:replace="~{common/layout :: header}"></div>
<div th:replace="~{common/layout :: sidebar}"></div>
<div class="container mt-5">
    <h1 class="mb-4">编辑检查项</h1>
    <form action="#" th:action="@{/checkitems/edit}" th:object="${checkitemDTO}" method="post" class="form-horizontal">
        <input type="hidden" th:field="*{checkitem.ciId}" />
        <div class="form-group">
            <label class="control-label col-sm-2">检查项名称:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitem.ciName}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">检查项内容:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitem.ciContent}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">意义:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitem.meaning}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">备注:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitem.remarks}" class="form-control"/>
            </div>
        </div>
        <h2 class="mt-4">详细信息</h2>
        <input type="hidden" th:field="*{checkitemDetailed.cdId}" />
        <div class="form-group">
            <label class="control-label col-sm-2">名称:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.name}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">单位:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.unit}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">最小范围:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.minrange}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">最大范围:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.maxrange}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">正常值:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.normalValue}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">正常值字符串:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.normalValueString}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">类型:</label>
            <div class="col-sm-10">
                <input type="number" th:field="*{checkitemDetailed.type}" class="form-control" required/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">备注:</label>
            <div class="col-sm-10">
                <input type="text" th:field="*{checkitemDetailed.remarks}" class="form-control"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">保存</button>
                <a href="/checkitems" class="btn btn-default">取消</a>
            </div>
        </div>
    </form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
    function validateDecimal(input) {
        const decimalPattern = /^\d+(\.\d{1,6})?$/;
        return decimalPattern.test(input);
    }
    document.getElementById('checkitemForm').addEventListener('submit', function(event) {
        const minrangeInput = document.getElementById('minrange').value;
        const maxrangeInput = document.getElementById('maxrange').value;

        if (!validateDecimal(minrangeInput) || !validateDecimal(maxrangeInput)) {
            event.preventDefault();
            alert('请输入有效的小数格式（最多六位小数）。');
        }
    });
</script>
</body>
</html>
